﻿using ApplicationBase.Core.Context;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ApplicationBase.Core.Command
{
    public interface ICommandFactory
    {
        public TCommand Produce<TCommand, TResponse>() where TCommand : BaseCommand<TResponse>, new();
    }

    public class CommandFactory : ICommandFactory
    {
        private readonly IServiceContext _serviceContext;
        public CommandFactory(IServiceContext serviceContext)
        {
            _serviceContext = serviceContext;
        }

        public TCommand Produce<TCommand, TResponse>() where TCommand : BaseCommand<TResponse>, new()
        {
            var cmd = new TCommand();
            cmd.ServiceContext = _serviceContext;
            return cmd;
        }
    }
}
